<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-sclae=1.0,user-scalable=0">
	<link rel="stylesheet" type="text/css" href="css/base.css">
	<title>xuluo</title>
</head>
<body style="font-size: 20px;line-height: 1.8;">
	<span>您已经离开页面0次<br>页面标题显示离开页面的次数</span>
	<script type="text/javascript">
		var hiddenProperty = 'hidden' in document ? 'hidden' :    
		    'webkitHidden' in document ? 'webkitHidden' :    
		    'mozHidden' in document ? 'mozHidden' :    
		    null;
		var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
		var n=0;
		var onVisibilityChange = function(){
		    if (!document[hiddenProperty]) {
		        document.body.innerHTML='您已经进入页面'+n+'次';
		    }else{
		    	n++;
		        document.title='您已经离开页面'+n+'次';
		    }
		};
		document.addEventListener(visibilityChangeEvent, onVisibilityChange);
	</script>
</body>
</html>